<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>整合 LayUI 编辑器</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="favicon.ico">
    <link rel="stylesheet" href="../../assets/css/main.css">
</head>
<body>

<div class="x-body">

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend>完整功能（没错，目前工具栏只有这么多）</legend>
    </fieldset>

    <textarea class="layui-textarea" id="LAY_demo1" style="display: none">昨夜西风凋碧树，独上高楼，望尽天涯路.</textarea>

    <div class="site-demo-button" style="margin-top: 20px;">
        <button class="layui-btn site-demo-layedit" data-type="content">获取编辑器内容</button>
        <button class="layui-btn site-demo-layedit" data-type="text">获取编辑器纯文本内容</button>
        <button class="layui-btn site-demo-layedit" data-type="selection">获取编辑器选中内容</button>
    </div>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend>自定义工具栏</legend>
    </fieldset>

    <div style="margin-bottom: 20px; width: 500px;">
        <textarea class="layui-textarea" id="LAY_demo2" style="display: none"></textarea>
    </div>

</div>
<script type="text/javascript" src="../../js/libs/jquery.min.js "></script>
<script type="text/javascript" src="../../js/libs/layui/layui.js"></script>
<script type="text/javascript" src="../../js/main.js"></script>
<script>
	layui.use(['layedit'], function(){
		var layedit = layui.layedit
			,$ = layui.jquery;

		// 配置编辑器
		layedit.set({
			uploadImage: {
				url: 'http://herosphp.r9it.com/admin/upload/qiniu', //接口url
				done: function(res) {
					//如果上传失败
					if(res.code == "000"){
						return layer.msg('上传失败');
					}
					//上传成功
				},
				error: function(message) {},
				type: 'post' //默认post
			}
		});

		//构建一个默认的编辑器
		var index = layedit.build('LAY_demo1');

		//编辑器外部操作
		var active = {
			content: function(){
				alert(layedit.getContent(index)); //获取编辑器内容
			}
			,text: function(){
				alert(layedit.getText(index)); //获取编辑器纯文本内容
			}
			,selection: function(){
				alert(layedit.getSelection(index));
			}
		};

		$('.site-demo-layedit').on('click', function(){
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});

		//自定义工具栏
		layedit.build('LAY_demo2', {
			tool: ['face', 'link', 'unlink', '|', 'left', 'center', 'right']
			,height: 100
		})
	});

</script>
</body>
</html>